import { getAllNewsType } from "@/api/news";

const state = {
  // 新闻类型数据
  newsTypeData: [],
};

const mutations = {
  // 改变新闻类型
  changeNewsType(state, payload) {
    state.newsTypeData = payload;
  },
};

const actions = {
  // 获取新闻类型
  getAllNewsType(context) {
    return new Promise(async (resolve) => {
      const data = await getAllNewsType();
      if (data.code === 0) {
        context.commit("changeNewsType", data.data);
        resolve("success");
      }
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
